package com.bbdjt.weixin.base.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import com.bbdjt.weixin.base.service.BaseService;
import tk.mybatis.mapper.common.Mapper;


public abstract class BaseServiceImpl<T> implements BaseService<T> {

    @Autowired
    protected Mapper<T> mapper;

    public Mapper<T> getMapper() {
        return mapper;
    }

    @Override
    public T selectByKey(Object key) {
        return mapper.selectByPrimaryKey(key);
    }
    
    public int insertSelective(T entity) {
    	//保存一个实体，null的属性不会保存，会使用数据库默认值
        return mapper.insertSelective(entity);
    }
    
    public int save(T entity) {
    	//保存一个实体，null的属性也会保存，不会使用数据库默认值
        return mapper.insert(entity);
    }

    public int delete(Object key) {
        return mapper.deleteByPrimaryKey(key);
    }

    public int updateAll(T entity) {
        return mapper.updateByPrimaryKey(entity);
    }

    public int updateNotNull(T entity) {
        return mapper.updateByPrimaryKeySelective(entity);
    }

    public List<T> selectByExample(Object example) {
        return mapper.selectByExample(example);
    }

    public int selectCount(T example) {
        return mapper.selectCount(example);
    }
      
    /**
     * 根据实体属性作为条件进行删除，查询条件使用等号 
     * 此操作杀伤力太大请谨慎使用
     * @param record
     * @return
     */
    public int deleteByWhere(T example) {
        return mapper.delete(example);
    }
    
}